<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function(){
            var div1 = document.getElementsByClassName("div1")[0];
            // 给整个页面绑定鼠标移动响应函数
            document.onmousemove = function(event){
                // pageX用于获取当前页面的水平坐标
                // clientX用于获取当前可见窗口的水平坐标
                var left = event.pageX;
                var top = event.pageY;
                // 给div1设置内联样式
                div1.style.left = left+"px";
                div1.style.top = top+"px";
            }
        }
    </script>
    <style>
        .div1{
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }
        .body{
            height: 2000px;
            width: 1200px;
        }
    </style>
</head>
<body>
    <div class="div1"></div>
</body>
</html>